#include <Keypad.h>
const byte ROWS = 5; //矩阵键盘行-五行
const byte COLS = 3; //矩阵键盘列-三列

// 每个位置对应的键盘中的内容
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'},
{'g','y','r'}
};
//指定 行 连接Ardunio的引脚
byte rowPins[ROWS] = {12, 11, 10, 9, 8};
//指定 列 连接Ardunio的引脚 
byte colPins[COLS] = {7, 6, 5};

//创建对象
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
  Serial.begin(9600);
}

void loop(){
  char key = keypad.getKey();// Read the key
  if (key){// 打印按下的键
      Serial.print("Key Pressed : ");
      Serial.println(key);
  }
}
